package jp.sourceforge.akjrcp.ffmpeg;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import jp.sourceforge.akjrcp.akj_betas.Messages;
import jp.sourceforge.akjrcp.dropsomething2.DropFileGenericParameterSetting;
import jp.sourceforge.akjrcp.dropsomething2.Setting;
import jp.sourceforge.akjrcp.ui.DirectryBasedExecuterListener;
import jp.sourceforge.akjrcp.util.FileNameUtils;
import jp.sourceforge.akjrcp.util.PathnameUtils;
import jp.sourceforge.akjrcp.util.ProcessMonitor;
import jp.sourceforge.akjrcp.util.ProcessPrinter;
import jp.sourceforge.akjrcp.util.StatusBarUtils;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.ui.PlatformUI;


public class FFMpegExecuter {
public static Log log = LogFactory.getLog(FFMpegExecuter.class);
private boolean useAvisynth;


//why ignore need?
private String[] ignoreAvisynthExtensions={"mpg","mp3","flv","ac3","mp2","m2a","aac","ogg","wav","vob","wma"};
private DirectryBasedExecuterListener executeListener;

private String exportDir;
private boolean sameDirectory;
private boolean backup;
private FFMpegPreference ffmpegPreference=new FFMpegPreference();
private Process process;
private boolean cancelling;


private File rootFile;

private File currentOutputFile;
private boolean renameSameFile=true; //allow same extension file

private boolean allowDemuxingFLV=true; //for drop mp3;
public int getGuessSize(){
	return ffmpegPreference.getGuessSize();
}
public void execute(File files[]){
	if(executeListener!=null){
		executeListener.beforeConvert();
	}
	
	for (int i = 0; i < files.length; i++) {
		rootFile=files[i];//for keep directory path
		execute(files[i]);
	}
	
	if(executeListener!=null){
		executeListener.afterConvert();
	}
}

private void execute(File file){
	if(file.isDirectory()){
		
		if(cancelling){
			log.info("cancel "+file);
			return;
		}
		
		String list[]=file.list();
		if(list!=null){
			for (int i = 0; i < list.length; i++) {
				execute(new File(file,list[i]));
			}
		}
	}else{
		//TODO should check file.
		inExecute(file);
	}
}

public void cancel(){
	log.info("called cancel");
	synchronized(this){
		log.info("cancell:"+System.currentTimeMillis());
		cancelling=true;
		}
	if(process!=null){
		process.destroy();
		log.info("maybe destroyed:"+process);
	}
	
}

private File toOutputFile(File file){
	
	String outputDir=file.getParent();
	String outputPath;
	if(!sameDirectory){
		outputDir=exportDir;
		String remain=PathnameUtils.getRemainPath(rootFile.getParent(),PathnameUtils.changeExtension(file.getAbsolutePath(),ffmpegPreference.getExtension()));
		log.info("remain:"+remain);
		outputPath=outputDir+"\\"+remain;
	}else{
		//same directory just rename it.
		outputPath=outputDir+"\\"+PathnameUtils.changeExtension(file.getName(),ffmpegPreference.getExtension());
	}
	
	log.info("save:"+outputPath);
	
	
	//if input and output same faild and return;
	if(file.getAbsolutePath().equals(outputPath)){
		if(renameSameFile){
			File newFile=FileNameUtils.makeBackupFile(file,"new");
			outputPath=newFile.getAbsolutePath();
			}else{
			//
			if(executeListener!=null){
				executeListener.faildConvert(file,DirectryBasedExecuterListener.ERROR_SAME_FILE);
				return null;
			}
			}
	}
	
	// check file can write;
	boolean overwrite=false;
	File tmpOutput=new File(outputPath);
	if(tmpOutput.exists() && !tmpOutput.canWrite()){
		//if the file is ready only
		if(executeListener!=null){
			executeListener.faildConvert(file,DirectryBasedExecuterListener.ERROR_CANT_OVERWRITE);
			return null;
		}
	}
	
	//ask overwrite
	if(!backup){
		
	if(tmpOutput.exists() && executeListener!=null){
		overwrite=executeListener.askOverwrite(tmpOutput);
		if(!overwrite){
			if(executeListener!=null){
			executeListener.faildConvert(file,DirectryBasedExecuterListener.ERROR_DONT_OVERWRITE);
			}
			return null;
		}
	}
	}else{
		//do backup
		File backUpFile=FileNameUtils.makeBackupFile(tmpOutput,"backup");
		if(backUpFile.exists()){
			boolean r=backUpFile.delete();
			if(!r){
				log.warn("delete faild "+backUpFile);
				if(executeListener!=null){
					executeListener.faildConvert(file,DirectryBasedExecuterListener.ERROR_CANT_BACK+" "+backUpFile);
					}
				return null;
			}else{
				log.info("delete success "+backUpFile);
			}
		}
		if(tmpOutput.exists()){
		boolean r=tmpOutput.renameTo(backUpFile);
		if(!r){
			log.warn("backup faild "+tmpOutput);
			if(executeListener!=null){
				executeListener.faildConvert(file,DirectryBasedExecuterListener.ERROR_CANT_BACK+" "+tmpOutput);
				}
			return null;
		}else{
			log.info("backup success "+tmpOutput);
		}
		}
	}
	
	return tmpOutput;
}

public static File makeBackupFile(File file,String addextension){
	int count=1;
	File bkfile=new File(file.getParentFile(),file.getName()+"."+addextension);
	while(bkfile.exists()){
		bkfile=new File(file.getParentFile(),file.getName()+"."+"("+count+")."+addextension);
		count++;
	}
	return bkfile;
}

public boolean execute(Setting setting){
	String input1=setting.getParameters().get(DropFileGenericParameterSetting.INPUT_VIDEO1);
	String audio1=setting.getParameters().get(DropFileGenericParameterSetting.INPUT_AUDIO1);
	File audio=null;
	if(audio1!=null && !"".equals(audio1)){
		audio=new File(audio1);
	}
	File input=new File(input1);
	rootFile=input;
	
	//TODO support avisynth
	
	return inExecute(input,audio);
}
protected boolean inExecute(File video1Input){
	return inExecute(video1Input,null);
}

protected String[] toAudioInputSupportedCommand(String video,String avs,String audio,File output){
	if(audio==null){
		log.warn("audio is null");
	}
	
	
	FLVInfomation info=new FFMpegFLVParser(ffmpegPreference.getFfmpegPath()).parseFile(new File(video));
	boolean video1HaveAudio=info.isHaveAudio();
	
	
	boolean hasAudio1Video=false;
	if(audio!=null){
		FLVInfomation ainfo=new FFMpegFLVParser(ffmpegPreference.getFfmpegPath()).parseFile(new File(audio));
		hasAudio1Video=ainfo.isHaveVideo();
	}
	
	if (output == null) {
		return null;
	}
	
	if (avs != null) {
		video=avs;
	}
	
	//warn
	//now input video stream must be 0 and audio stream must be 1 if audio has video
	FFMpegInput videoInput=new FFMpegInput(video);
	if(video1HaveAudio){
		videoInput.setMap("0.0:0.0");
	}
	
	FFMpegInput audioInput=new FFMpegInput(audio);
	if(video1HaveAudio){
	if(hasAudio1Video){
		audioInput.setMap("1.1:0.1");
	}else{
		audioInput.setMap("1.0:0.1");
	}
	}
	
	String[] commands=ffmpegPreference.toCommand(new FFMpegInput[]{videoInput,audioInput},output.getAbsolutePath());
	return commands;
}
protected boolean inExecute(File video1Input,File audio1Input){
	boolean ret=true;
	ProcessPrinter printer=new ErrorCatchProcessPrinter();
	
	
	
	try {
		printer.printOutput("######## start "+new Date()+"\n");//TODO move up
		
		if(ffmpegPreference.getGeneration()==1){//
			printer.printOutput("[info]"+Messages.getString("info.old_ffmpeg")+"\n");//TODO move up
		}
	} catch (IOException e3) {
		// TODO Auto-generated catch block
		e3.printStackTrace();
	}
	if(ffmpegPreference.getFfmpegPath()==null){
		log.warn("ffmpeg not found:set ffmpegPath in preference");
	}
	if(cancelling){
		log.info("cancel "+video1Input);
		return false;
	}
	
	
	File tmpOutput=toOutputFile(video1Input);
	if(tmpOutput==null){
		return false;//do somethin faild;
	}
	
	setCurrentOutputFile(tmpOutput);
	
	File input=null;
	File avs=null;
	//use avs
	boolean avsAvailable = false;
	if(ffmpegPreference!=null){
		avsAvailable=FFMpegUtils.isAvisynthAvailable(new File(ffmpegPreference.getFfmpegPath()));
	}
	
	//ignore avisynth
	for (int i = 0; i < ignoreAvisynthExtensions.length; i++) {
		if(video1Input.getName().toLowerCase().endsWith(ignoreAvisynthExtensions[i])){
			useAvisynth=false;
			log.info("dont use avisynth for "+ignoreAvisynthExtensions[i]);
			break;
		}
	}
	log.info(useAvisynth+","+avsAvailable);
	if(useAvisynth){
	if(avsAvailable){
		try {
			avs = File.createTempFile("avs", ".avs");
			FileWriter writer = new FileWriter(avs);
			writer.write(FFMpegUtils.toAVSScript(video1Input
					.getAbsolutePath()));
			writer.close();
			printer.printOutput("[info] "+Messages.getString("info.use_avisynth")+"\n");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}else{
		try {
			printer.printError("[warn] "+Messages.getString("err.avisynth_not_working")+"\n");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	}
	
	input=video1Input;
	
	//execute command
	log.info("avs:"+avs);
	String avsPath=null;
	if(avs!=null){
		avsPath=avs.getAbsolutePath();
	}
	log.info("avsPath:"+avsPath);
	//
	
	
	
	
	if(process!=null){
		//anyway old process must die.
		process.destroy();
	}
	
	process = null;
	
	
	//because threa some time rag to know cancell
	if(cancelling){
		log.info("cancel "+video1Input);
		return false;
	}
	//finally make file dirs.
	
	tmpOutput.getParentFile().mkdirs();
	File tmpAudio=null;
	File tmpVideo=null;
	
	
	String message="";
	try {
		
		String[] commands=null;
		
		//-- one pass encode
		if(!ffmpegPreference.isTwoPassEncode()){
		//demux VP6 FLV :old phasion
		if(allowDemuxingFLV && input.getName().toLowerCase().endsWith(".flv") && PlatformUI.getPreferenceStore().getBoolean(FFMpegUI.DEMUX_SOME_VIDEO)&& avsPath==null){
			FLVInfomation flvInfo=new FFMpegFLVParser(ffmpegPreference.getFfmpegPath()).parseFile(input);
			if(flvInfo.getVideoCodec().equals(FLVInfomation.FLV4)){//TODO has audio test
				tmpAudio=File.createTempFile("vp6", ".mp3");
				tmpAudio.deleteOnExit();
				String command[]=FFMpegCommandUtil.makeCopyAudioCommand(ffmpegPreference.getFfmpegPath(), input.getAbsolutePath(), tmpAudio.getAbsolutePath());
				SimpleCommandExecuter executer1=new SimpleCommandExecuter(command);
				PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar("FLV4(VP6) audio demuxing.please wait."));
				executer1.execute();
				
				log.info("demuxed audio");
				tmpVideo=File.createTempFile("vp6", ".flv");//much better. 
				tmpVideo.deleteOnExit();
				String command2[]=FFMpegCommandUtil.makeCopyVideoCommand(ffmpegPreference.getFfmpegPath(), input.getAbsolutePath(), tmpVideo.getAbsolutePath());
				SimpleCommandExecuter executer2=new SimpleCommandExecuter(command2);
				PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar("FLV4(VP6) video demuxing.please wait."));
				
				executer2.execute();
				log.info("demuxed video");
				//now VP6 FLV only
				if(audio1Input==null){
				commands=ffmpegPreference.toCommand(new FFMpegInput[]{new FFMpegInput(tmpAudio.getAbsolutePath(),"mp3"),new FFMpegInput(tmpVideo.getAbsolutePath())},tmpOutput.getAbsolutePath());
				}else{
					commands=toAudioInputSupportedCommand(tmpVideo.getAbsolutePath(),null,audio1Input.getAbsolutePath(),tmpOutput);	
					
				}
			}else{
				
				//normal flv create normal option
				if(audio1Input==null){
				commands=ffmpegPreference.toCommand(input.getAbsolutePath(),avsPath,tmpOutput.getAbsolutePath());
				}else{
					commands=toAudioInputSupportedCommand(input.getAbsolutePath(),avsPath,audio1Input.getAbsolutePath(),tmpOutput);		
				}
			}
		}else{
			
			//normal files create normal option
			
			if(audio1Input==null){
			commands=ffmpegPreference.toCommand(input.getAbsolutePath(),avsPath,tmpOutput.getAbsolutePath());
			}else{
				commands=toAudioInputSupportedCommand(input.getAbsolutePath(),avsPath,audio1Input.getAbsolutePath(),tmpOutput);	
			}
		}
		
		if(commands==null){
			log.warn("null command");
			if(executeListener!=null){
				executeListener.faildConvert(video1Input,"");
			}
			return false;
		}
		
		if(executeListener!=null){

			executeListener.startConvert(video1Input);
		}
		if(cancelling){
			log.info("canceled "+video1Input);
			return false;
			}
		
		Runtime runtime=Runtime.getRuntime();

		
		try {
			printer.printOutput(toDebugArray(commands));
		} catch (IOException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		log.info("start process:"+process+","+ArrayUtils.toString(commands));
		
		
		
		
		process = runtime.exec(commands);
		
		//log.info("start process:"+process+","+ArrayUtils.toString(commands));
		log.info("process:"+System.currentTimeMillis()+","+cancelling);
		
		ProcessMonitor monitor=new ProcessMonitor(process,printer);
		monitor.startMonitor();
		
		try {
			if(!cancelling){
			process.waitFor();
			
			int result=process.exitValue();
			if(result!=0){
				ret=false;
			if(result==1){
				log.info("exit-value:"+result);
				
				
			}else{
				printer.printError("[error] "+result+"\n");
				//-1073741795 unknown
				if(result==-1073741819){
					PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("error.happend")+":"+Messages.getString("error.memory")));
					log.warn("exit-value:"+result+"maybe memory error");
					printer.printError("[error] "+Messages.getString("error.avisynth")+"\n");
				}else if(result==-1073741515){//this happend when pthreadGC2.dll not found.
					PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("error.happend")+":"+Messages.getString("error.pthreadGC2")));
					log.warn("exit-value:"+result+"pthreadGC2.dll not found");
					printer.printError("[error] "+Messages.getString("error.pthreadGC2")+"\n");
					printer.printError(""+Messages.getString("hint.pthreadGC2")+"\n");
				}else if(result==-1073741795){
					PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("error.happend")+":"+Messages.getString("error.unknowncpu")));
					log.warn("exit-value:"+result+" maybe x264 dont support your CPU");
				}
					else{
				
					log.warn("exit-value:"+result);
					//unknown memory
					PlatformUI.getWorkbench().getDisplay().asyncExec(new StatusBarUtils.ShowStatusBar(Messages.getString("error.happend")+":"+result));
					
					}
				
				//anyway warn and log
				Thread.sleep(1000);
				}
			}
			}else{
				//cancelled
			log.info("finally cancel "+video1Input);
			return false;
			}
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}else{
			if(allowDemuxingFLV && input.getName().toLowerCase().endsWith(".flv") && PlatformUI.getPreferenceStore().getBoolean(FFMpegUI.DEMUX_SOME_VIDEO)&& avsPath==null){
				FLVInfomation flvInfo=new FFMpegFLVParser(ffmpegPreference.getFfmpegPath()).parseFile(input);
				if(flvInfo.getVideoCodec().equals(FLVInfomation.FLV4)){
					tmpAudio=File.createTempFile("vp6", ".mp3");
					tmpAudio.deleteOnExit();
					String command[]=FFMpegCommandUtil.makeCopyAudioCommand(ffmpegPreference.getFfmpegPath(), input.getAbsolutePath(), tmpAudio.getAbsolutePath());
					SimpleCommandExecuter executer1=new SimpleCommandExecuter(command);
					executer1.execute();
					log.info("demuxed audio");
					tmpVideo=File.createTempFile("vp6", ".avi");
					tmpVideo.deleteOnExit();
					String command2[]=FFMpegCommandUtil.makeCopyVideoCommand(ffmpegPreference.getFfmpegPath(), input.getAbsolutePath(), tmpVideo.getAbsolutePath());
					SimpleCommandExecuter executer2=new SimpleCommandExecuter(command2);
					executer2.execute();
					log.info("demuxed video");
					//now VP6 FLV only
					
					twoPassEncode(new FFMpegInput[]{new FFMpegInput(tmpAudio.getAbsolutePath(),"mp3"),new FFMpegInput(tmpVideo.getAbsolutePath())},tmpOutput,ffmpegPreference);
				}else{
					twoPassEncode(input,avsPath,tmpOutput,ffmpegPreference);
				}
			}else{
				twoPassEncode(input,avsPath,tmpOutput,ffmpegPreference);
			}
			
		}
	} catch (IOException e1) {
		//maybe catch not supported codecs.
		e1.printStackTrace();
		process.destroy();
		message=e1.getMessage();
		ret=false;
	}finally{
//		remove tmpavs;
		if(avs!=null){
			avs.delete();
		}
		
		if(tmpAudio!=null){
			tmpAudio.delete();
			tmpAudio=null;
		}
		
		if(tmpVideo!=null){
			tmpVideo.delete();
			tmpVideo=null;
		}
		
	}
	
	//call finish
	if(executeListener!=null){
		if(ret){
			executeListener.endConvert(video1Input);
			}
		else{
			executeListener.faildConvert(video1Input,message);
			}
		}
	
	process=null;
	//cancelling=false; damm.this time cancell all only.
	return ret;
}

public void twoPassEncode(File input,String avsPath,File tmpOutput,FFMpegPreference preferences) throws IOException{
	FFMpegInput[] inputs=new FFMpegInput[1];
	if(avsPath!=null){
		inputs[0]=new FFMpegInput(avsPath);
	}else{
		inputs[0]=new FFMpegInput(input.getAbsolutePath());
	}
	twoPassEncode(inputs, tmpOutput, preferences);
}
public void twoPassEncode(FFMpegInput[] inputs,File tmpOutput,FFMpegPreference preferences) throws IOException{

	//make log file output+_log
	//make 1passtmp file tmp_ + output
	String passlog=System.getProperty("java.io.tmpdir")+System.currentTimeMillis()+"_log";
	new File(passlog).deleteOnExit();
	File onePassFile=new File(tmpOutput.getParent(),"tmp_"+tmpOutput.getName());
	String[] commands1pass=preferences.toCommandPass1(inputs,passlog,onePassFile.getAbsolutePath());
	if(commands1pass==null){
		log.warn("null command");
		return;
	}
	
	Runtime runtime=Runtime.getRuntime();
	ProcessPrinter printer=new ErrorCatchProcessPrinter();
	try {
		printer.printOutput(toDebugArray(commands1pass));
	} catch (IOException e2) {
		// TODO Auto-generated catch block
		e2.printStackTrace();
	}
	
	//show start
	if(executeListener!=null){
		executeListener.startConvert(new File(inputs[0].getPath()));
	}
	
	log.info("start process:"+process+","+ArrayUtils.toString(commands1pass));
	
	
	process = runtime.exec(commands1pass);
	
	ProcessMonitor monitor=new ProcessMonitor(process,printer);
	monitor.startMonitor();
	
	try {
		if(!cancelling){
		process.waitFor();
		}else{
		log.info("finally cancel ");
		return;
		}
		
		int exit=process.exitValue();
		if(exit!=0){
			throw new IOException("exit:"+exit);
		}
	} catch (InterruptedException e) {
		e.printStackTrace();
		throw new IOException(e.getMessage());
	}
	
	if(cancelling){
		log.info("canceled ");
	}
	boolean deleteOnePass=onePassFile.delete();
	if(!deleteOnePass){
		log.warn("delete one pass file failed:"+onePassFile.getAbsolutePath());
		
	}
	String[] commands2pass=preferences.toCommandPass2(inputs,passlog,tmpOutput.getAbsolutePath());
	if(commands2pass==null){
		log.warn("null command");
		return;
	}
	
	
	
	try {
		printer.printOutput(toDebugArray(commands2pass));
	} catch (IOException e2) {
		e2.printStackTrace();
		throw new IOException(e2.getMessage());
	}
	log.info("start process:"+process+","+ArrayUtils.toString(commands1pass));
	
	if(!cancelling){
	process = runtime.exec(commands2pass);
	}
	
	ProcessMonitor monitor2=new ProcessMonitor(process,printer);
	monitor2.startMonitor();
	
	try {
		if(!cancelling){
		process.waitFor();
		}else{
		log.info("finally cancel ");
		return;
		}
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	
	//done
	new File(passlog).delete();//anyway delete log
	
	int exit=process.exitValue();
	if(exit!=0){
		throw new IOException("exit:"+exit);
	}
}

public class TestMonitor implements DirectryBasedExecuterListener{

	public void beforeConvert() {
		// TODO Auto-generated method stub
		
	}

	public void afterConvert() {
		// TODO Auto-generated method stub
		
	}

	public void startConvert(File file) {
		// TODO Auto-generated method stub
		
	}

	public void endConvert(File file) {
		// TODO Auto-generated method stub
		
	}

	public void faildConvert(File file, String message) {
		log.info("faild:"+file);
	}

	public void printProcess(String line) {
		// TODO Auto-generated method stub
		
	}

	public boolean askOverwrite(File output) {
		// TODO Auto-generated method stub
		return false;
	}
	
}

public static String toDebugArray(String[] array){
	String v="";
	for (int i = 0; i < array.length; i++) {
		v+="\""+array[i]+"\""+" ";
	}
	return v+"\n";
}

public boolean isBackup() {
	return backup;
}

public void setBackup(boolean backup) {
	this.backup = backup;
}

public DirectryBasedExecuterListener getExecuteListener() {
	return executeListener;
}

public void setExecuteListener(DirectryBasedExecuterListener executeListener) {
	this.executeListener = executeListener;
}

public String getExportDir() {
	return exportDir;
}

public void setExportDir(String exportDir) {
	this.exportDir = exportDir;
}

public FFMpegPreference getFfmpegPreference() {
	return ffmpegPreference;
}

public void setFfmpegPreference(FFMpegPreference ffmpegPreference) {
	this.ffmpegPreference = ffmpegPreference;
}

public String[] getIgnoreAvisynthExtensions() {
	return ignoreAvisynthExtensions;
}

public void setIgnoreAvisynthExtensions(String[] ignoreAvisynthExtensions) {
	this.ignoreAvisynthExtensions = ignoreAvisynthExtensions;
}

public boolean isSameDirectory() {
	return sameDirectory;
}

public void setSameDirectory(boolean sameDirectory) {
	this.sameDirectory = sameDirectory;
}

public boolean isUseAvisynth() {
	return useAvisynth;
}

public void setUseAvisynth(boolean useAvisynth) {
	this.useAvisynth = useAvisynth;
}

public class ErrorCatchProcessPrinter implements ProcessPrinter{
	public void printOutput(String output) throws IOException {
		print(output);
	}

	public void printError(String error)  throws IOException{
		print(error);
	}

	private void print(String line) throws IOException{
		if(executeListener!=null){
			executeListener.printProcess(line);
			}
		log.debug(line);
		
		if(line.indexOf(DirectryBasedExecuterListener.ERROR_NOTSUPPORTED_VIDEO)!=-1){
			//cancel();
			//ignore only this time.
			
			if(line.indexOf("flv")!=-1){
				log.info("flv is sensitive");
				
				
			}else{
				//please don't use old ffmpeg.exe
				//throw new IOException(DirectryBasedExecuterListener.ERROR_NOTSUPPORTED_VIDEO);
				log.info("unsupported:");
				}
			}
		
	}
	
}

public File getCurrentOutputFile() {
	return currentOutputFile;
}
public void setCurrentOutputFile(File currentOutputFile) {
	this.currentOutputFile = currentOutputFile;
}
public boolean isAllowDemuxingFLV() {
	return allowDemuxingFLV;
}
public void setAllowDemuxingFLV(boolean allowDemuxingFLV) {
	this.allowDemuxingFLV = allowDemuxingFLV;
}

}
